using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;

namespace Terra.Data.Entities.Identity;

/// <summary>
/// 刷新令牌实体
/// </summary>
[Table("RefreshTokens")]
[Comment("刷新令牌表")]
[Index(nameof(Token), IsUnique = true)]
public class RefreshToken : AuditEntityBase<Guid>
{
    /// <summary>
    /// 用户ID
    /// </summary>
    [Required]
    [Comment("用户ID")]
    public Guid UserId { get; set; }

    /// <summary>
    /// 令牌值
    /// </summary>
    [Required]
    [MaxLength(512)]
    [Comment("刷新令牌值")]
    public string Token { get; set; }

    /// <summary>
    /// 过期时间
    /// </summary>
    [Required]
    [Comment("过期时间")]
    public DateTime ExpiresAt { get; set; }

    /// <summary>
    /// 是否已使用
    /// </summary>
    [Required]
    [Comment("是否已使用")]
    public bool IsUsed { get; set; }

    /// <summary>
    /// 是否已撤销
    /// </summary>
    [Required]
    [Comment("是否已撤销")]
    public bool IsRevoked { get; set; }

    /// <summary>
    /// 用户代理
    /// </summary>
    [MaxLength(512)]
    [Comment("用户代理信息")]
    public string UserAgent { get; set; }

    /// <summary>
    /// IP地址
    /// </summary>
    [MaxLength(64)]
    [Comment("IP地址")]
    public string IpAddress { get; set; }

    /// <summary>
    /// 关联的用户
    /// </summary>
    [ForeignKey(nameof(UserId))]
    public virtual User User { get; set; }
}